package com.group3.config;/**
 * UploadConfig
 *
 * @author HY
 * 2021/07/14 8:39
 **/


import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import org.springframework.util.unit.DataUnit;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.MultipartConfigElement;

/**
 * ClassName UploadConfig
 * Description
 * @author 余久
 * @Date 2021/07/14 8:39
 **/

@Configuration
public class UploadConfig {

    @Bean
    public MultipartConfigElement getMultipartConfig() {
        MultipartConfigFactory config = new MultipartConfigFactory();
        // 设置上传文件的单个大小限制(200*1024L = 200kb？)
        config.setMaxFileSize(DataSize.of(10, DataUnit.MEGABYTES));
        // 设置总的上传的大小限制
        config.setMaxRequestSize(DataSize.of(10, DataUnit.MEGABYTES));
        // 设置临时保存目录
        config.setLocation("/");
        // 创建一个上传配置
        return config.createMultipartConfig();
    }

//    @Value("${file.staticAccessPath}")
//    private String staticAccessPath;
//    @Value("${file.uploadFolder}")
//    private String uploadFolder;
//
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler(staticAccessPath).addResourceLocations("file:" + uploadFolder);
//    }
}
